<template>
  <div class="clearfix">
    <div style="font-size:150%">
      代码扫描master面板
    </div>
    <div slot="header" class="clearfix">
      项目选择
      <el-select v-model="projectName" placeholder="请选择" @change="changeProject()">
        <el-option
          v-for="item in projectList"
          :key="item.id"
          :label="item.name"
          :value="item.id">
        </el-option>
      </el-select>
      <el-tooltip class="item" effect="dark" content="cap数据每天更新，点击fresh获取最新数据" placement="right-end">
        <el-button @click="refreshInfo()" type="primary" style="position: absolute;right: 50px;">刷新</el-button>
      </el-tooltip>
    </div>

    <shopee-table
      :data="tableData"
      border
      style="width: 100%;top:20px"
      v-loading="loading">
      <shopee-table-column
        prop="url"
        label="模块">
      </shopee-table-column>
      <shopee-table-column
        prop="high"
        sortable
        label="严重问题个数">
      </shopee-table-column>
      <shopee-table-column
        prop="middle"
        sortable
        label="中等问题个数">
      </shopee-table-column>
      <shopee-table-column
        prop="low"
        sortable
        label="简单问题个数">
      </shopee-table-column>
    </shopee-table>
  </div>
</template>

<script>
import {api, getRequest} from "@/api/commit";

export default {
  name: "CAPMasterTable",
  data() {
    return {
      loading: false,
      tableData: [],
      projectName: "CRM",
      projectList: [{
        id: "Membership",
        name: 'MBS'
      }, {
        id: "CRM",
        name: 'CRM'
      }],
    };
  },
  methods: {

    changeProject() {
      // location.reload()
      this.init_data()
    },
    refreshInfo() {
      this.loading = true;
      getRequest(api['get_master_cap_info'], {project_name: this.projectName, cache: false}).then((res) => {
        res = res.resultReturn
        res = res.data

        this.tableData = res
        for (let i = 0; i < this.tableData.length; i++) {
          let link = "https://cap.epd.i.shopee.io/issue?status=1&status=2&status=3&status=4&ruleTypes=1&ruleTypes=2&ruleTypes=3&ruleTypes=4&ruleTypes=5&ruleTypes=6&ruleTypes=7&ruleTypes=8&ruleTypes=9&ruleTypes=10&ruleTypes=99&branchName=master" + "&pid=" + this.tableData[i].pid
          let high_link = link + "&ruleLevels=1&assign"
          this.tableData[i].high =
            <a target="_blank" href={high_link}> {this.tableData[i].high} </a>
          let middle_link = link + "&ruleLevels=2&assign"
          this.tableData[i].middle =
            <a target="_blank" href={middle_link}> {this.tableData[i].middle} </a>
          let low_link = link + "&ruleLevels=3&assign"
          console.info(high_link)
          console.info(low_link)
          console.info(middle_link)
          this.tableData[i].low =
            <a target="_blank" href={low_link}> {this.tableData[i].low} </a>
        }
        this.loading = false;

      }, (error) => {
        console.info(error)
      })
    },
    init_data() {
      this.loading = true;
      getRequest(api['get_master_cap_info'], {project_name: this.projectName}).then((res) => {
        res = res.resultReturn
        res = res.data
        this.tableData = res
        for (let i = 0; i < this.tableData.length; i++) {
          let link = "https://cap.epd.i.shopee.io/issue?status=1&status=2&status=3&status=4&ruleTypes=1&ruleTypes=2&ruleTypes=3&ruleTypes=4&ruleTypes=5&ruleTypes=6&ruleTypes=7&ruleTypes=8&ruleTypes=9&ruleTypes=10&ruleTypes=99&branchName=master" + "&pid=" + this.tableData[i].pid
          let high_link = link + "&ruleLevels=1&assign"
          this.tableData[i].high =
            <a target="_blank" href={high_link}> {this.tableData[i].high} </a>
          let middle_link = link + "&ruleLevels=2&assign"
          this.tableData[i].middle =
            <a target="_blank" href={middle_link}> {this.tableData[i].middle} </a>
          let low_link = link + "&ruleLevels=3&assign"
          console.info(high_link)
          console.info(low_link)
          console.info(middle_link)
          this.tableData[i].low =
            <a target="_blank" href={low_link}> {this.tableData[i].low} </a>
        }

        this.loading = false;
      }, (error) => {
        console.info(error)
      })
    }
  }, created() {
    this.init_data()

  }

};
</script>
